package com.zhang.controller;

import com.zhang.entity.DeviceInfo;
import com.zhang.entity.ExecutionResults;
import com.zhang.entity.response.ResponseResult;
import com.zhang.service.DeviceInfoService;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * User: 张
 * Date: 2024-11-14
 * Time: 21:29
 * Description:
 */
@RestController
@RequestMapping("/info")
public class DeviceController {
    @Autowired
    private DeviceInfoService deviceInfoService;

    @PostMapping("/getDeviceInfo")
    public ResponseResult<Object> getDeviceInfo(@RequestBody DeviceInfo deviceInfo,
                                                @Param("pageNum") Integer pageNum,
                                                @Param("pageSize") Integer pageSize ) {
        return ResponseResult.success(deviceInfoService.getDeviceInfo(pageNum,pageSize,deviceInfo));
    }

    @PostMapping("/addDeviceInfo")
    public ResponseResult<Object> addDeviceInfo(@RequestBody DeviceInfo deviceInfo) {
        return deviceInfoService.addDeviceInfo(deviceInfo) ? ResponseResult.success() : ResponseResult.error();
    }

    @PutMapping("/updateDeviceInfo")
    public ResponseResult<Object> updateDeviceInfo(@RequestBody DeviceInfo deviceInfo) {
        return deviceInfoService.updateDeviceInfo(deviceInfo) ? ResponseResult.success() : ResponseResult.error();
    }

    @DeleteMapping("/deleteDeviceInfo")
    public ResponseResult<Object> deleteDeviceInfo(@RequestBody DeviceInfo deviceInfo) {
        return deviceInfoService.deleteDeviceInfo(deviceInfo.getId()) ? ResponseResult.success() : ResponseResult.error();
    }

    @PostMapping("/getDeviceLog")
    public ResponseResult<Object> getDeviceLog(@RequestBody ExecutionResults executionResults,
                                               @Param("pageNum") Integer pageNum,
                                               @Param("pageSize") Integer pageSize){
        return ResponseResult.success(deviceInfoService.getDeviceLog(executionResults,pageSize,pageNum));
    }
}
